# The "Install Jalview.app"

> Despite the name this is still quite a generic installer and could be adapted (removing one string "Jalview" in the Applescript properties) to work with any application.

## Running the application

It:
- Finds various locations such as system Applications folder, user Applications folder, its own location;
- Looks for a .app bundle in the same folder as itself that (i) isn't itself and (ii) starts with "Jalview" (this can be changed to "" or null for full generality);
- Creates an enhanced dialog (using Dialog Toolkit Plus) asking the user if they want to "Install for all users" or "Install for current user only (User's name)" with a checkbox asking whether to "Add to current user's Dock". The icon imagery uses the found .app's own icon alongside an arrow and Applications folder icon stored in the installer's .app bundle.
- Then uses Finder to copy the .app to the specified location (this may require admin privileges which will work like normal Finder-based installation).
- If appropriate, uses a shell command to add the copy of the application to the Dock.

### Some notes on its running

1) Progress bar:
There is sometimes (first time?) a longer pause when the Install Jalview.app initialises. In applescript a progress bar window can be launched, but this can't be made to go away, just made inactive when the enhanced dialog is ready. I have used some code from https://www.macscripter.net/t/make-progress-bar-disappear-before-displaying-a-dialog/75001/5 to create a progress bar that can be closed, but this also takes a second or two to appear(!) so is perhaps of limited use.

2) Adding to Dock:
There is some commented out code that ought to create a new Dock item using applescript, but it doesn't seem to work, so a tried and tested shell one-liner recipe is used.


## How to make the "Install Jalview.app"

0) You will need Dialog Toolkit Plus (https://www.macscripter.net/t/dialog-toolkit-plus/73994).  You should put the "Dialog Toolkit Plus.scptd" folder in "~/Library/Script Libraries".

1) Open "utils/macos_dmg/Install Jalview/Install Jalview.applescript" in Script Editor.
Note that running applescripts in Script Editor are often slightly different than when made into an .app bundle.  Some that I have found:
- When duplicating with Finder, the "Keep both/Replace/Cancel" dialog doesn't appear, and an error about file already existing happens instead.  Ignore that and go ahead and make the .app anyway!
- The bespoke progress bar code cannot run from Script Editor as it has to be on the main thread.  In the .app bundle it is.
- After saving or compiling (the ">" play icon and the hammer icon) you can happily run the script in the Script Editor.  If you try and run a second time without saving or compiling first then you might get some opaque error.  This doesn't happen with the .app version because it runs anew each time.

2) Export as an application (File -> Export... then choose File Format: Application and make sure the options are all unticked except for "Run-only" which you should tick).  This creates "Install Jalview.app" with no extra resources and default icon.

3) Add the resources that are needed (this includes some icons and the Dialog Toolkit Plus library).  The easiest way to do this is to untar "utils/macos_dmg/Install Jalview/Install Jalview_app_items.tgz" over the "Install Jalview.app" folder.

4) The untar replaces the default Contents/Resources/applet.icns but for good measure, find Install Jalview.app in Finder and open the "Get Info" dialog.  At the top left is the .app bundle's icon.  Find "ArrowInstall.icns" in "utils/macos_dmg/Install Jalview" in a Finder window and drag it onto the icon at the top left of the Get Info dialog you have open.

That should have created the app.  A version created using the above methods can be found at "utils/macos_dmg/Install Jalview/Install Jalview.app" and this is tarred into "utils/macos_dmg/Install Jalview/Install Jalview_app.tgz" for install4j to unpack into the DMG when it's being created.
